import java.io.*;
import java.net.*;


public class ChatClient {
	Socket cliente;
	DataInputStream in;
	DataOutputStream out;
	public ChatClient(String host, int port) {

		try {
			cliente = new Socket(host, port);
			in = new DataInputStream(cliente.getInputStream());
			out = new DataOutputStream(cliente.getOutputStream());
			
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public DataInputStream getIn() {
		return in;
	}
	
	public void enviaMsg(String msg) {
		try {
			out.writeUTF(msg);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	
	public int recebeMsg() {
		int x=0;
		try {
			x = in.readInt();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return x;
	}
	
	public String recebe() {
		String msg = "";
		try {
			msg = in.readUTF();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			System.out.println("Erro Servidor:");
			e.printStackTrace();
			System.out.println(e.getMessage());
		}
		return msg;
	}	
	public void closeChat() {
		try {
			in.close();
			out.close();
			cliente.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
